<?php

/**
 * This is the model class for table "Prize".
 *
 * The followings are the available columns in table 'Prize':
 * @property string $id
 * @property string $name
 * @property string $description
 * @property string $value
 * @property string $imageId
 * @property string $created
 * @property string $updated
 * @property integer $deleted
 */
class Prize extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className the class name
	 * @return Prize the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Prize';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('id, name, description, value', 'required'),
			array('deleted', 'numerical', 'integerOnly'=>true),
			array('id, imageId', 'length', 'max'=>10),
			array('name', 'length', 'max'=>255),
			array('imageId, created, updated', 'safe'),
			array('id, name, value, imageId, created, updated, deleted', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
		);
	}

	/**
	 * @return array attached behaviors.
	 */
	public function behaviors()
	{
		return array(
			'ext.auditbehavior.AuditBehavior',
			'ext.deletedbehavior.DeletedBehavior',
			'ImgRecordBehavior',
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('label','Id'),
			'name' => Yii::t('label','Name'),
			'description' => Yii::t('label','Description'),
			'value' => Yii::t('label','Value (€)'),
			'imageId' => Yii::t('label','Image'),
			'created' => Yii::t('label','Created'),
			'updated' => Yii::t('label','Updated'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('t.id',$this->id,true);
		$criteria->compare('t.name',$this->name,true);
		$criteria->compare('t.imageId',$this->imageId,true);
		$criteria->compare('t.created',$this->created,true);
		$criteria->compare('t.updated',$this->updated,true);

		$criteria->addCondition('t.deleted=0');

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}